package com.allwees.bs.module.core.dynamic.strategy.moudule;

import cn.hutool.core.util.ReflectUtil;
import com.allwees.bs.module.core.dynamic.data.DynamicInjectQuery;
import com.allwees.bs.module.core.dynamic.strategy.DynamicInjectStrategy;
import com.allwees.core.common.util.DynamicFieldUtil;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

@Setter
public class DynamicInjectCategoryFullnameStrategy extends DynamicInjectStrategy {

    private DynamicInjectQuery query;

    @Override
    public Object inject(String key, Object target) {
        if(!ReflectUtil.hasField(target.getClass(),"categoryFullname")){
            return target;
        }
        Map<String, Object> map = new HashMap<>();
        map.put("categoryFullname", query.findCategoryFullname(key));
        return DynamicFieldUtil.getTarget(target, map);
    }
}
